package com.hbnu.test.www.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP_server02 {
    public static void main(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(6666)) {
            Socket socket = serverSocket.accept();
            InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream();
            byte[] receivedata = new byte[1024];
            int len = inputStream.read(receivedata);
            System.out.println("客户端发送来的消息为：" + new String(receivedata, 0, len));
            //向客户端发送消息
            byte[] bytes = "收到客户端消息".getBytes();
            outputStream.write(bytes);

            } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
